<?php
namespace App\Http\Admin\Controllers\Version;
use App\Http\Controllers\Controller;
use Faker\Core\Version;
use Hlcreation\Basic\Helper;
use App\Services\version\VersionServices;
use Illuminate\Http\Request;
use App\Requests\VersionRequest;
use Illuminate\Support\Facades\DB;
use App\Services\store\StoreServices;

class VersionController extends Controller
{


    public function __construct(VersionServices $services)
    {
        $this->services = $services;
    }


    //添加版本
    public function add(VersionRequest $request){

        $all = $request->all();
        $userInfo = Helper::getPost('userinfo');
        $all['creator_uid']=$userInfo['user_info']['id'];

        $data = $this->services->versionSave($all);
        if($data){
            return Helper::toJson("创建成功", 200);
        }else{
            return Helper::toJson("创建失败", 400);
        }


    }


    //编辑版本
    public function update(VersionRequest $request){
        $userInfo = Helper::getPost('userinfo');
        $all = $request->except(['id']);  //排除id
        $id = $request->only('id');  //只要ID
        $all['creator_uid']=$userInfo['user_info']['id'];
        $data = $this->services->versionUpdate($id,$all);
        if($data){
            return Helper::toJson("编辑成功", 200);
        }else{
            return Helper::toJson("编辑失败", 400);
        }


    }



    //版本详情
    public function info(Request $request){
        $id = Helper::getPost('id');
        $data = $this->services->versionInfo($id);
        return  Helper::toJson('版本详情 ',200,$data);
    }



    //版本列表
    public function ls(Request $request){

        $where['limit'] = Helper::getPost('limit');
        $where['page'] = Helper::getPost('page');

        $where['type'] = Helper::getPost('type');

        $list = $this->services->getList($where);

        return  Helper::toJson('版本列表 ',200,$list);

    }

    //删除
    public function delete(){
        $id = Helper::getPost('id');
        $data = $this->services->versionDelete($id);
        if($data){
            return Helper::toJson("删除成功", 200);
        }else{
            return Helper::toJson("删除失败", 400);
        }

    }













}
